import 'package:jiffy/jiffy.dart';
import 'package:safetymonitor/app/components/custom_modele/custom_title_chart_page.dart';
import 'package:safetymonitor/app/components/custom_refresh.dart';
import 'package:safetymonitor/app/core/core.dart';
import 'package:safetymonitor/app/core/ext/widget_extension.dart';
import 'package:safetymonitor/app/data/entities/application/preventive_rectification_entity.dart';
import 'package:safetymonitor/generated/assets.dart';
import 'package:safetymonitor/modules/home/snap_shot_danger/basic_common_widget.dart';
import 'controller.dart';

///待完成
//1.admin账号新增隐患   派发给一个分公司（13600010002 ），分公司账号派发给一个人（13700010002），只有这个人有隐患整改权限
class NoCompletedPage extends StatelessWidget {
  NoCompletedPage({super.key});

  final controller = Get.put(NoCompletedController());

  @override
  Widget build(BuildContext context) {
    return GetBuilder(
        init: controller,
        builder: (_) {
          return Scaffold(
            // key: controller.riskRightScaffoldKey,
            backgroundColor: AppColors.bg_color_grey,
            body: Container(
              padding: EdgeInsets.only(top: 12.w, right: 14.w, left: 14.w),
              child: Column(
                children: [
                  Row(
                    children: [
                      Expanded(
                        child: _getSearchEnterWidget(),
                      ),
                      AppGaps.hGap8,
                      _screen(),
                      AppGaps.vGap10,
                    ],
                  ),
                  AppGaps.vGap12,
                  Expanded(
                      child: CustomEasyRefreshList<PreventiveRectificationEntity>(
                    key: controller.globalKey,
                    dataLoad: controller.getCompanyDeviceListEntity,
                    itemBuilder: (item, index) {
                      return _itemWidget(item);
                    },
                  )),
                ],
              ),
            ),
            // endDrawer: CustomEndDrawer(
            //   centerContext: Column(
            //     children: [
            //
            //     ],
            //   ),
            //   reset: controller.reset,
            //   confirm: controller.confirm,
            // ),
          );
        });
  }
  ///搜索框
  Widget _getSearchEnterWidget() {
    return Container(
        height: 38.w,
        padding: EdgeInsets.symmetric(horizontal: 12.w),
        alignment: Alignment.center,
        decoration: BoxDecoration(
            color: Colors.white,
            border: Border.all(color: const Color(0xffF0F0F0), width: 1.w),
            borderRadius: BorderRadius.all(Radius.circular(8.w))),
        child: Row(
          children: [
            SvgPicture.asset(
              Assets.svgSearch,
              width: 16.w,
            ),
            Expanded(
                child: TextField(
                    keyboardType: TextInputType.text,
                    textInputAction: TextInputAction.done,
                    controller:
                        TextEditingController(text: controller.searchX),
                    onChanged: (value) {
                      controller.searchX = value;
                      controller.refreshPage();
                    },
                    style: TextStyle(
                        color: const Color(0xff222222),
                        fontWeight: FontWeight.w400,
                        fontSize: 14.sp),
                    decoration: InputDecoration(
                      counterText: '',
                      //防止适配不居中
                      isCollapsed: true,
                      border:
                          const OutlineInputBorder(borderSide: BorderSide.none),
                      contentPadding: EdgeInsets.only(left: 8.w),
                      hintText: '请输入隐患名称',
                      hintStyle: TextStyle(
                          fontSize: 14.sp,
                          fontWeight: FontWeight.w400,
                          color: const Color(0xffA0A7B5)),
                    )))
          ],
        ));
  }

  /// 标题
  Widget _title(String title, String? value) {
    return Row(
      children: [
        Text(
          title,
          style: TextStyle(
            color: const Color(0xffA5A6B5),
            fontSize: 13.sp,
            fontWeight: FontWeight.w400,
          ),
        ),
        if (value != null)
          Expanded(
              child: Text(
            value,
            style: TextStyle(
              color: const Color(0xff495061),
              fontSize: 13.sp,
              fontWeight: FontWeight.w400,
            ),
          )),
      ],
    );
  }

  Widget _itemWidget(PreventiveRectificationEntity item) {
    return CustomTitleChartPage(
        titleRightWidget: BasicCommonDangerWidget.getCommonStateView(item.status),
        title:'隐患名称:${item.preventiveName}',
        child: Column(
          children: [
            _title('责任单位:', item.companyName),
            AppGaps.vGap5,
            _title('整改期限:',item.rectificationDeadline!=0?Jiffy.parseFromMillisecondsSinceEpoch(item.rectificationDeadline).format(pattern: 'yyyy-MM-dd HH:mm:ss'):''),
            AppGaps.vGap5,
            _title('问题描述:',  item.problemDesc)
          ],
        )).clickOnce((){
          controller.onClickDetail(item);
    });
  }

  ///筛选
  Widget _screen() {
    return Container(
      width: 38.w,
      height: 38.w,
      alignment: Alignment.center,
      decoration: BoxDecoration(
          color: Colors.white, borderRadius: BorderRadius.circular(8.w)),
      child: SvgPicture.asset(
        'assets/svg/icon_search_screen.svg',
        width: 16.w,
      ),
    ).click(controller.onFilterButtonPressed);
  }
}
